using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPCoco.Tasks
{
    public abstract class TargetedTask<T> : FiniteTime
    {
         public TargetedTask(T target, float duration)
            : base(duration)
        {
            Target = target;
        }

        public TargetedTask(float duration)
            : this(default(T), duration)
        {

        }

        T target;

        public T Target
        {
            get { return target; }
            set 
            { 
                target = value;
                Owner = value;
            }
        }

        T _target;

        public override void Initialize()
        {
            base.Initialize();
            _target = target;
            InitializeWithTarget(_target);
        }

        public abstract void InitializeWithTarget(T target);

        public override void Update(float time)
        {
            base.Update(time);
            UpdateWithTarget(_target, time);
        }

        public abstract void UpdateWithTarget(T target, float time);

        public override void Finish()
        {
            base.Finish();
            FinishWithTarget(_target);
        }

        public virtual void FinishWithTarget(T target) { }
    }
}
